﻿/*
 * Ext JS Library 2.0 Alpha 1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */


Ext.onReady(function(){

    Ext.BLANK_IMAGE_URL = '../../resources/images/default/s.gif';
    Ext.QuickTips.init();
    
   // shared reader
    var reader = new Ext.data.ArrayReader({}, [
       {name: 'cd'},
       {name: 'subject_name'},
       {name: 'lecture_score', type: 'float'},
       {name: 'subject_score', type: 'float'},
       {name: 'academicyear'},
       {name: 'term'}
    ]);
    btn = !!document.all? document.all['draw'] : !!document.getElementById? document.getElementById('draw') : null;
    
    btn.onclick=function() {
    	tabs.items.each(function(item){
                        if(item.closable){
                            tabs.remove(item);
                        }
                    });
    	selectObj=!!document.all? document.all['year'] : !!document.getElementById? document.getElementById('year') : null;
    	yearValue=selectObj.value;
    	termobj=!!document.all? document.all['termvalue'] : !!document.getElementById? document.getElementById('termvalue') : null;
    	termValue = termobj.value;
    	results = ds.queryBy(function(record) {
        return record.get('academicyear') == yearValue && parseInt(record.get('term')) == parseInt(termValue);

    	});
 			_N_Tab++;   	
			_tab_id=_TAB_PRE+'BAR'+'-'+_N_Tab;
			_canvas_id='canvas'+_N_Tab;
  		jsBar = new Bar();
			tabs.add({
								id:_tab_id,
  		          title: 'example up down',
  		          iconCls: 'chart-bar',
  		          html: jsBar.mkDiv('', '', 0, (tabs.floating ? 0 : tabs.getPosition()[1]+30), tabs.getInnerWidth(), tabs.getInnerHeight()-tabs.getFrameHeight(), '', _canvas_id, false,false,jsBar.jsc_ie),
  		          closable:true
  		}).show();
			jsBar.chartTitle='<B><font style="font-size:20px;font-family:Arial,Helvetica,sans-serif;color:black;">test haha<\/font></B>';
  		jsBar.canvasWidth = 550;
  		jsBar.canvasHeight = 400;
  		jsBar.canvasID = _canvas_id;
  		jsBar.canvasLeft = 60;
  		jsBar.canvasTop = 40;
  		jsBar.canvasRight = 10;
  		jsBar.canvasBottom = 60;
  		jsBar.dataMin=0;
  		jsBar.dataMax=8;
  		jsBar.barBoder={"width":"1","color":"#000000","style":"solid"};
  		jsBar.paints=['008000','FFFF00'];
  		jsBar.XAxisTitle='XTest';
  		jsBar.YAxisTitle='<img src=images/yAxisTitle.png></img>';
  		aprop = new AxisProperties(false);
  		aprop.dataProperties = new DataProperties();
  		aprop.labelProperties = new LabelProperties();
  		aprop.labelProperties.showTicks = 1;
  		aprop.labelProperties.showGridLines = 0;
  		aprop.dataProperties.setUserDefinedScale(0, 10, 10);
  		jsBar.axisProperties = aprop;
  		jsBar.legend = new LegendProperties(JSCHART_RIGHT, 1, 100, 20);
			jsBar.legendLabels=['Subject Score','Lecture Score'];
	   	jsBar.axisLabels.length=0;
    	jsBar.datas.length = 0;
    	_sdatas=[];
    	_ldatas=[];
    	for (rind=0; rind<results.getCount(); rind++) {
    		rs = results.get(rind);
				jsBar.axisLabels[jsBar.axisLabels.length]=rs.get('subject_name');
				
				_sdatas[_sdatas.length]=rs.get('subject_score');
				_ldatas[_ldatas.length]=rs.get('lecture_score');
				
    	}
				jsBar.datas[jsBar.datas.length]=_sdatas;
				jsBar.datas[jsBar.datas.length]=_ldatas;
  		jsBar.drawChart();
  		
    }
    var ds = new Ext.data.Store({
    				proxy: new Ext.data.MemoryProxy(dummyData),
            reader: reader,
            data: dummyData
            });
    var tabs = new Ext.TabPanel({
    		id:'chartCanvasTabs',
        renderTo:document.body,
        resizeTabs:true, // turn on tab resizing
        minTabWidth: 115,
        tabWidth:135,
        floating:false,
        enableTabScroll:true,
        width:600,
        height:480,
        defaults: {autoScroll:true},
        plugins: new Ext.ux.TabCloseMenu()
    });
_N_Tab=0;
_TAB_PRE='_tabPanel-';
_CANVAS_PRE='_chartCanvas-';

  

    ds.load({params:{start:0, limit:25, forumId: 4}});
    // tab generation code
    
    
	});

// Array data for the grids
dummyData = [
    ['1','Management','80','70','2007/2008', '1'],
    ['2','Business','60','60','2007/2008', '1'],
    ['3','Algorithm','70','70','2007/2008', '2'],
    ['4','CRM','85','70','2007/2008', '2'],
    ['5','ERP','90','80','2008/2009', '1'],
    ['6','English','100','90','2008/2009', '1'],
    ['7',' Religion','90','75','2008/2009', '1']
];

function setvalue(obj) {
	termobj=!!document.all? document.all['termvalue'] : !!document.getElementById? document.getElementById('termvalue') : null;
	termobj.value=obj.value;
};